package com.dragon.mmochat.model.mergeServer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import com.dragon.mmochat.model.role.MmochatFriend;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class MergeStep2Model1 {
	private int id;
	// 我的好友:roleId->好友基本信息
	private Map<Integer, MmochatFriend> myDearFriends = null;
	// 黑名单:roleId->好友基本信息
	private Map<Integer, MmochatFriend> myEnermys = null;
	// 我的徒弟,roleId->name
	private Map<Integer, String> students = null;

	public void addRoleIdValue(int add) {
		List<MmochatFriend> list = new ArrayList<MmochatFriend>();
		if (myDearFriends != null) {
			for (MmochatFriend f : myDearFriends.values()) {
				f.setRoleId(f.getRoleId() + add);
				list.add(f);
			}
			myDearFriends.clear();
			for (MmochatFriend f : list) {
				myDearFriends.put(f.getRoleId(), f);
			}
		}

		if (myEnermys != null) {
			list.clear();
			for (MmochatFriend f : myEnermys.values()) {
				f.setRoleId(f.getRoleId() + add);
				list.add(f);
			}
			myEnermys.clear();
			for (MmochatFriend f : list) {
				myEnermys.put(f.getRoleId(), f);
			}
		}

		if (students != null) {
			Map<Integer, String> studentsBak = new ConcurrentHashMap<Integer, String>();
			for (Entry<Integer, String> entry : students.entrySet()) {
				Integer roleId = entry.getKey();
				String name = entry.getValue();
				if (roleId != null) {
					studentsBak.put(roleId + add, name);
				}
			}
			students = studentsBak;
		}
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Map<Integer, MmochatFriend> getMyDearFriends() {
		return myDearFriends;
	}

	public void setMyDearFriends(Map<Integer, MmochatFriend> myDearFriends) {
		this.myDearFriends = myDearFriends;
	}

	public Map<Integer, MmochatFriend> getMyEnermys() {
		return myEnermys;
	}

	public void setMyEnermys(Map<Integer, MmochatFriend> myEnermys) {
		this.myEnermys = myEnermys;
	}

	public Map<Integer, String> getStudents() {
		return students;
	}

	public void setStudents(Map<Integer, String> students) {
		this.students = students;
	}

	public String getGson_friends() {
		if (myDearFriends == null) {
			return null;
		}
		Gson gson = new Gson();
		return gson.toJson(myDearFriends,
				new TypeToken<Map<Integer, MmochatFriend>>() {
				}.getType());
	}

	public String getGson_enermys() {
		if (myEnermys == null) {
			return null;
		}
		Gson gson = new Gson();
		return gson.toJson(myEnermys,
				new TypeToken<Map<Integer, MmochatFriend>>() {
				}.getType());
	}

	public String getGson_students() {
		if (students == null) {
			return null;
		}
		Gson gson = new Gson();
		return gson.toJson(students, new TypeToken<Map<Integer, String>>() {
		}.getType());
	}

}
